﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Collections;

/// <summary>
/// Summary description for XL_KH
/// </summary>
public class XL_CTDH
{
    protected DataRow Dong;
    protected static String Tenbang = "CHI_TIET_DON_HANG";

    public int MaCTDH
    {
        get
        {
            return (int)this.Dong["MCT"];
        }
        set
        {
            //this.Dong["MCT"] = value;
        }
    }

    public string MSP
    {
        get
        {
            return this.Dong["MSP"].ToString();
        }
        set
        {
            this.Dong["MSP"] = value;
        }
    }

    public int Soluong
    {
        get
        {
            return (int)this.Dong["Soluongdat"];
        }
        set
        {
            this.Dong["Soluongdat"] = value;
        }
    }

    public long Giadonhang
    {
        get
        {
            return long.Parse(this.Dong["Giadonhang"].ToString());
        }
        set
        {
            this.Dong["Giadonhang"] = value;
        }
    }


    public int MaDH
    {
        get
        {
            return (int)this.Dong["MDH"];
        }
        set
        {
            this.Dong["MDH"] = value;
        }
    }
    
     public XL_CTDH()
    {
        String sql="select * from " + Tenbang;
        DataTable Bang  = DataProvider.ExecuteStructureQuery(sql);
        Dong = Bang.NewRow();
        Bang.Rows.Add(Dong);
    }

    public XL_CTDH(DataRow DongN)
	{
		//
		// TODO: Add constructor logic here
		//
        this.Dong = DongN;
	}

    //public static ArrayList Doc_danh_sach()
    //{
    //    ArrayList Kq = new ArrayList();
    //    string sql = "Select * ";
    //    sql += " From DON_HANG dh,TAI_KHOAN tk ";
    //    sql += " Where dh.mtk = tk.mtk";
    //    DataTable Bang = DataProvider.ExecuteQuery(sql);
    //    foreach (DataRow DT in Bang.Rows)
    //    {
    //        XL_DH LTK = new XL_DH(DT);
    //        Kq.Add(LTK);
    //    }
    //    return Kq;

    //}

    public static XL_CTDH Tim_CTDH_theo_MaDH(int MaDH) // Tim chinh xac chi tiet don hang theo ma don hang
    {
        String sql = "select * from " + Tenbang;
        sql += " where MDH = " + MaDH;
        DataTable Bang = DataProvider.ExecuteQuery(sql);
        XL_CTDH CTDH;

        if (Bang.Rows.Count > 0)
        {
            foreach (DataRow DT in Bang.Rows)
            {
                CTDH = new XL_CTDH(DT);
                return CTDH;
            }
        }
        return null;        
        

    }


    public void Ghi() // Ghi tung dong
    {
        //String sql = "select * from " + Tenbang;
        //sql += " Where MTK = " + this.MTK;
        //DataTable BDH = DataProvider.ExecuteQuery(sql);
        //DataRow DH = BDH.Rows[0];
       
        //DH["MDH"] = this.MaDH;
        //DH["Ngaydat"] = this.Ngaydat;
        //DH["Tinhtrang"] = this.TinhtrangTT;

        //Ghi Bang
        
        DataProvider.Save(this.Dong, Tenbang);

    }
    public void Xoa()
    {

        //String sql = "select * from " + Tenbang;
        //sql += " Where MTK = " + this.MTK;
        //DataTable BDH = DataProvider.ExecuteQuery(sql);
        //DataRow DH = BDH.Rows[0];
       
        DataProvider.Delete(this.Dong, Tenbang);

    }

}

  